<?php

class Truck_type_info extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'Truck_type_info':
	 * @var integer $id
	 * @var string $type_name
	 * @var string $remark
	 * @var integer $state
	 * @var string $create_time
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'truck_type_info';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('type_name','length','max'=>20),
			array('remark','length','max'=>100),
			array('compute_ratio', 'numerical','integerOnly'=>true,'min'=>0,'max'=>1000),
			//array('effect_date,lapse_date', 'match','pattern' => '/\d{4}-\d{2}$/','message'=>'{attribute} 必须为日期型(年-月)'),
			array('type_name,compute_ratio', 'required'),
		);
	}
	
	/**
	 * Prepares attributes before performing validation.
	 */
	protected function beforeValidate($on)//在验证之前将无需用户输入的字段写入
	{
		if($this->isNewRecord){
			$this->state=0;
			$this->create_time=date('Y-m-d G:i:s');
		}
		return true;
	}
	
	protected function afterValidate($on)//在验证之前将无需用户输入的字段写入
	{	
		if($this->hasErrors()) return;
		//$this->effect_date.='-01';
		//$this->lapse_date.='-01';
		$this->compute_ratio/=100;
		return true;
	}
	
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '索引号',
			'type_name' => '车型名称',
			//'effect_date' => '生效日期',
			//'lapse_date' => '失效日期',
			'compute_ratio' => '绩效计算比率(%)',
			'remark' => '备注说明',
			'state' => '状态',
			'create_time' => '创建时间',
		);
	}
}